def softwrap(files=[])
  files.each do |file|
    contents = read_lines(file)
    write_lines(file, contents)
  end
end

def read_lines(file)
  File.open(file, 'r') do |ins|
    contents = ins.readlines()
  end
end

def write_lines(file, contents)
  File.open(file, 'w+') do |outs|
    contents.each do |x|
      x = get_softwrap_line(x)
      x.gsub!(/(\t| )+/, ' ')
      outs.print(x)
    end
  end
end

def get_softwrap_line(str)
  str.chomp!()
  return "\n\n" if str.length() == 0
  return str << ' '
end

softwrap(ARGV)
